package com.wuliu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.domain.entity.BasCust;
import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.system.domain.BasTruckInfo;
import com.wuliu.system.mapper.BasTruckInfoMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author realue
 * @version 1.0
 * @date 2023-11-05 19:30
 */
@RestController
@RequestMapping("/applet/truckInfo")
@Api(tags = {"车辆管理控制器"})
public class BasTruckInfoController {

    @Resource
    private BasTruckInfoMapper basTruckInfoMapper;

    @GetMapping("/list")
    @ApiOperation(value = "查询车辆列表", notes = "")
    @ApiImplicitParam(name = "key", value = "关键字(车牌号/司机姓名/司机电话)", dataType = "String", paramType = "query")
    public ApiResult<List<BasTruckInfo>> list(String key) {
        BasCust cust = SecurityUtils.getBasCust();
        LambdaQueryWrapper<BasTruckInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BasTruckInfo::getSysAccount, cust.getSysAccount())
                .eq(BasTruckInfo::getStatus, 1);
        if (StringUtils.isNotEmpty(key)) {
            wrapper.and(wq -> wq.eq(BasTruckInfo::getPlateNo, key)).or()
                    .eq(BasTruckInfo::getRespPerson, key)
                    .eq(BasTruckInfo::getRespTel, key);
        }
        return ApiResult.success(basTruckInfoMapper.selectList(wrapper));
    }
}
